﻿using L6_RegionNavigation.WithParameter.Models;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Navigation;
using Prism.Navigation.Regions;

namespace L6_RegionNavigation.WithParameter.ViewModels
{
    public class MainWindowViewModel : BindableBase
    {
        private readonly IRegionManager regionManager;

        public DelegateCommand ShowPersonDetailCommand { get; set; }

        public MainWindowViewModel(IRegionManager regionManager)
        {
            this.regionManager = regionManager;

            ShowPersonDetailCommand = new DelegateCommand(ExcuteShowPersonDetail);
        }

        private void ExcuteShowPersonDetail()
        {
            Person p = new Person()
            {
                Id = 1,
                Name = "姓名",
                Age = 20
            };

            NavigationParameters parameters = new NavigationParameters();
            parameters.Add("model", p);

            regionManager.RequestNavigate("ContentRegion", "PersonAttributeView", parameters);
        }
    }
}
